Key takeaways

We analyzed effect of TCMB interest rates on economy and our results :

-Interest rates don’t work alone even if it’s a big instrument to balance the dollar

-Interest rates how can affect to Turkey about technology and science exports but not all the development just high techonogy export

Overview and Preliminary

We get TCMB interest rate as a main data and USD/TRY, technology indicators exports, data it was a small data but very open the interpretation

Objectives:

Explore and Cleaning data

Our main dataset was small and clean but when we need comparisons other data we needed the make it compatible with main data. Firstly, we need necessary libraries:

knitr::opts_chunk$set(echo = TRUE,warning=FALSE)
library(readr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(readxl)
library(tidyr)
library(plotly)

Data Loading

Explore the interest_rate data frame with str() function.

str(interest_rate) # to see dataframe format
## Classes 'tbl_df', 'tbl' and 'data.frame':    20 obs. of  2 variables:
##  $ year: POSIXct, format: "2010-05-20" "2010-12-17" ...
##  $ rate: num  7 6.5 6.25 5.75 5.5 5 4.5 10 9.5 8.75 ...
str(usd_tl)
## Classes 'spec_tbl_df', 'tbl_df', 'tbl' and 'data.frame': 120 obs. of  6 variables:
##  $ Date    : chr  "Dec 19" "Nov 19" "Oct 19" "Sep 19" ...
##  $ Price   : num  5.78 5.75 5.71 5.65 5.83 ...
##  $ Open    : num  5.75 5.71 5.65 5.83 5.58 ...
##  $ High    : num  5.79 5.79 5.94 5.84 5.86 ...
##  $ Low     : num  5.73 5.67 5.64 5.63 5.44 ...
##  $ Change %: chr  "0.54%" "0.60%" "1.13%" "-3.12%" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   Date = col_character(),
##   ..   Price = col_double(),
##   ..   Open = col_double(),
##   ..   High = col_double(),
##   ..   Low = col_double(),
##   ..   `Change %` = col_character()
##   .. )
str(consumer_price_index[1:5])
## Classes 'tbl_df', 'tbl' and 'data.frame':    151 obs. of  5 variables:
##  $ Date    : chr  "2007-05" "2007-06" "2007-07" "2007-08" ...
##  $ Turkey  : num  140 140 139 139 140 ...
##  $ Region_1: num  144 144 142 142 144 ...
##  $ Region_2: num  141 141 141 140 141 ...
##  $ Region_3: num  142 142 141 141 142 ...
str(producer_price_index[1:5])
## Classes 'tbl_df', 'tbl' and 'data.frame':    151 obs. of  5 variables:
##  $ Date        : chr  "2007-05" "2007-06" "2007-07" "2007-08" ...
##  $ Turkey      : num  139 139 139 140 142 ...
##  $ ppi_region_1: num  152 152 153 158 156 ...
##  $ ppi_region_2: num  154 155 155 162 162 ...
##  $ ppi_region_3: num  197 196 199 211 197 ...

Data Type Converting

Since the “year” column appears a categorical variable on consumer price index, producer price index and interest rate datasets, it should be converted it to date with as.Date functon to more convenient analysis. Also, some columns are renamed to easy understanding.

interest_rate <- interest_rate %>%
  mutate(date = year(year))
usd_tl_dp <- usd_tl %>% select("Date","Price") 
usd_tl_dp$Date <- parse_date_time(usd_tl_dp$Date,orders = c("my")) 
usd_tl_dp$Date <- as.Date(as.POSIXct(usd_tl_dp$Date))
consumer_price_index$Date <- as.Date(paste(consumer_price_index$Date,"-01",sep=""))
producer_price_index$Date <- as.Date(paste(producer_price_index$Date,"-01",sep=""))
colnames(tech) <- c("country_name","country","date","indicator_name","indicator_code","value")

A new dataset was prepared for changes in the CPI and PPI overall Turkey. At the same time, the dataset was manipulated by normalizing the datatable with gather() function.

general_price_index <- data.frame(consumer_price_index$Date, consumer_price_index$Turkey, producer_price_index$Turkey)
names(general_price_index) <- c("Date", "CPI" , "PPI")
general_price_index <- general_price_index %>%
  gather(key = "index_type", "index_value", "CPI", "PPI")
general_price_index$index_type <- as.factor(general_price_index$index_type)
str(general_price_index)
## 'data.frame':    302 obs. of  3 variables:
##  $ Date       : Date, format: "2007-05-01" "2007-06-01" ...
##  $ index_type : Factor w/ 2 levels "CPI","PPI": 1 1 1 1 1 1 1 1 1 1 ...
##  $ index_value: num  140 140 139 139 140 ...

Analysis

Let’s look at the graph of the interest rates change over the years.

c <- ggplot(interest_rate, aes(x=year, y=rate, group=1)) +
  geom_line(color = "blue") +
  geom_point(color = "blue") +
  labs(title = "TCMB Interest Rates",
       x = "Year of observation",
       y = "Interest Rates") + 
  theme_light() +
  theme(axis.text.x = element_text(colour = "grey0", size = 10, angle = 30, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey20", size = 10),
        text = element_text(size = 12)) 
c <- ggplotly(c)
c

As can be seen from the graph, interest rates determined by TCMB showed volatility and increased momentum. ## USD/TRY relation

interest_rate$year <- as.POSIXct(interest_rate$year)
usd_tl_dp$Date <- as.POSIXct(usd_tl_dp$Date)
graph_usdTL <- ggplot(interest_rate,aes(interest_rate$year,interest_rate$rate)) +
  geom_line(color="blue") +
  scale_y_continuous("Interest Rate(%)",
  sec.axis = sec_axis(~ . * 0.33, name = "USD/TRY")) +
  theme_light() +
  ggtitle("TCMB Interest Rates")+
  xlab("Years") +
  theme(plot.title = element_text(color = "cadetblue4", size=20))
graph_usdTL <- graph_usdTL +
  geom_line(data=usd_tl_dp, aes(Date,Price*3), color="red") + 
  ggtitle(("TCMB Interest Rates vs USD/TRY"))
graph_usdTL

## Inflation vs. Interest Rates There are many discussions on the relationship between interest and inflation. Inflation refers to the rate at which prices for goods and services rise. To examine this relationship, let us examine the producer price index and consumer price index data. Although the graph values show an increasing change, it is also necessary to calculate the monthly and annual changes in interest rates in order to more convenient analysis.

general_price_index <- general_price_index %>% group_by(index_type) %>%
  mutate(monthly_change = (index_value / lag(index_value) -1)*100, yearly_change = (index_value / lag(index_value, 12) -1)*100) %>%
  gather(key = "change_type", "change_value", "monthly_change", "yearly_change")

We have changed the column names for easier visualizing.

general_price_index$change_type[general_price_index$change_type == "monthly_change"] <- "Monthly"
general_price_index$change_type[general_price_index$change_type == "yearly_change"] <- "Yearly"

The relationship between CPI and PPI is shown below.

graph_index <- general_price_index %>% ggplot() +              # basic graphical object
  geom_line(aes(Date, index_value, color = index_type)) +
  labs(title = "Price Indexes",
       x = "Year of observation",
       y = "Indexes")+
  theme_light() +
  theme(axis.text.x = element_text(colour = "grey10", size = 10, angle = 45, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey10", size = 10),
        text = element_text(size = 12),
        legend.title = element_text("Index Type"))
graph_index <- ggplotly(graph_index)
graph_index

Changes on PPI and CPI:

graph_index_change <- general_price_index %>% ggplot() +              
  geom_line(aes(x=Date, y=change_value, color = change_type), linetype = 0) +
  facet_wrap(general_price_index$index_type, dir = "v") +
  coord_cartesian()+
  labs(title = "Change in price indexes",
       x = "Year of observation",
       y = "Change")+
  theme_light() +
  theme(legend.title = element_text("Change Type"),
        axis.text.x = element_text(colour = "grey20", size = 10, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey20", size = 10),
        text = element_text(size = 12))
graph_index_change <- ggplotly(graph_index_change)
graph_index_change

Our studies show that the inflation rate rises gradually over the years.

average <- general_price_index %>% 
  mutate(Year = year(Date)) %>%
  group_by(Year, index_type) %>% 
  summarize(average = mean(index_value))
graph_average <- ggplot(data = average) +
  geom_bar(mapping = aes(x=Year, y=average, fill = index_type), stat = "identity") +
  facet_wrap(average$index_type) +
  coord_cartesian()+
  labs(title = "Change in price indexes",
       x = "Year of observation",
       y = "Change") +
  theme_light() +
  theme(legend.title = element_text("Change Type"),
        axis.text.x = element_text(colour = "grey20", size = 10, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey20", size = 10),
        text = element_text(size = 12))
graph_average <- ggplotly(graph_average)
graph_average

## Technology Exports vs. Interest Rate ### Dot Plot the techonology data and see what it has

library(scales)
## 
## Attaching package: 'scales'
## The following object is masked from 'package:readr':
## 
##     col_factor
theme_set(theme_classic())
# Plot
ggplot(tech, aes(x=indicator_name, y=value)) + 
  geom_point(col='#e67e22', size=3) +   # Draw points
  geom_segment(aes(x=indicator_name, 
                   xend=indicator_name, 
                   y=min(value), 
                   yend=max(value)), 
               linetype="dashed", 
               size=0.1) +  # Draw dashed lines
  labs(title="Dot Plot",
       subtitle="İndicators vs Values") +  
  coord_flip()

In this plot show us, high techonology exports are above the other so we can take this indicator to do analysis with interest rate. However, we are gonna use two more indicators which are Charges for the use of intellectual property, payments (BoP, current US\() and Charges for the use of intellectual property, receipts (BoP, current US\)) to be sure for our analysis.

Analysis of technology indicators

ht <- tech %>% 
  group_by(indicator_name, value, date) %>%
  filter(indicator_name == "High-technology exports (current US$)") %>%
  summarise(mean_value = mean(value/1000000)) %>% 
  arrange(desc(value)) %>% group_by(date)
ch <- tech %>% group_by(indicator_name,value,date) %>% 
  filter(indicator_name == "Charges for the use of intellectual property, payments (BoP, current US$)")%>%
  arrange(desc(value))%>%group_by(date)
unht <- tech %>% group_by(date) %>%
  summarise(mean_value = mean(value/1000000)) %>% 
  arrange(desc(mean_value))%>%
  filter(date > 2010 & date < 2018)

Analysis for hig tech to make usable data for compare interest rate. We are going to calculate mean value for all indicators to compare other plots. The other one which is using just high tech to find any increasing, then take just Charges for the use of intellectual property, payments (BoP, current US$). The last one is going to filter significant dates used the same with interest rate.

Compare between High tech and the other indicators

Firstly we looked the indictaors which can be usable the select the benefical one.

all <- inner_join(ht,unht,by = c("date"))
ggplot(all, aes(x = date)) + 
  geom_line(aes(y = mean_value.x, colour = "High-technology exports")) +
  geom_line(aes(y = mean_value.y, colour = "other mean")) +
  xlab("Years") + ylab("Normalized Prices")  +
  theme_light()

The plot shows us there is a relation between indicators and interest rate. When the interest rate is going to down, some indicators which are making big exports are going to up. ## Join two tables to analyze

indicators <- tech %>% group_by(date, indicator_name) %>% 
  filter(indicator_name %in% c("High-technology exports (current US$)", "Charges for the use of intellectual property, payments (BoP, current US$)","Charges for the use of intellectual property, receipts (BoP, current US$)")) %>% 
  group_by(indicator_name)
all2 <- inner_join(interest_rate, indicators, by = c("date"))
g <- ggplot(indicators, aes(x = date, y = value/100000000, colour=indicator_name)) + 
  geom_line() + 
  geom_point()+ 
  labs(x="",
       y = "Tech Invest Value") + 
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        axis.text.x = element_text(size = 10)) 
g <- g +  geom_smooth(data=all2, aes(date,rate)) + 
  ggtitle(("Tech Invest Rates vs Interest rates")) +
  theme(axis.text.x = element_text(colour = "grey20", size = 10, angle = 45, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey20", size = 10),
        text = element_text(size = 7),
        legend.position = "top", legend.box = "vertical" )
g
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

theme_set(theme_bw())
g <- ggplot(all2, aes(date, value/100000000)) + 
  labs(title="TECH INVEST VS INTEREST RATE")
g + geom_jitter(aes(col=indicator_name, size=rate)) + 
  geom_smooth(aes(col=indicator_name), method="lm", se=F)+theme_light() +
  theme(axis.text.x = element_text(colour = "grey20", size = 10, angle = 45, hjust = 0.5, vjust = 0.5),
        axis.text.y = element_text(colour = "grey20", size = 10),
        text = element_text(size = 8),
        legend.position = "right", legend.box = "vertical" )

graph1 <- ggplot(unht,aes(date,mean_value/35)) +
  ggtitle("Tech Invest Rates")+xlab("Years")+ylab("Rates(%)") +
  geom_smooth(se = FALSE, stat='summary',
              fun.y=quantile,fun.args=list(probs=0.9),color='blue') +
  theme(plot.title = element_text(color = "grey20",size=20)) +
  scale_y_continuous("Interest Rate(%)",
                     sec.axis = sec_axis(~ . * 0.5,name = "Interest rates"))
graph1 <- graph1 +
  geom_smooth(se = FALSE, data=all2,aes(date,rate),color='red') + 
  ggtitle(("Tech Invest Rates vs Interest rates")) +
  theme(plot.title = element_text(color = "grey20",size=20)) 
graph1
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

## Conclusion of techonolgy export and interest rate relationship And again we are going to see rates and indicators name. The last tech exports analysis is going to compare between tech export and interest rates. However we are not going to say that there is not enough evidence to make a decision.

Relationship Between Interest Rate And Foreign Trade

The last day of each month were added as a date, the foreign trade figure of each month were added as a value and the valid interest rate for each date were added to rows for each date. Interest rates which did not coincide with any date were excluded from the dataset. 2010-05-31 is the first date and 2019-10-31 is the last date. Assigning the columns in the dataset to variables to increase readability

Exports <- foreign_trade$exports/1000000
Imports <- foreign_trade$imports/1000000
Balance <- foreign_trade$balance/1000000
Date <- foreign_trade$date
Rate <- foreign_trade$interest_rate
Deficit <- Balance*(-1)

Graph of exports (USD in billions)

ggplot(foreign_trade, aes(x = date, y = exports)) +
  geom_bar(stat ='identity', color = 'gray', fill = 'gray') +
  geom_line(stat ='identity', color = 'gray') +
  labs(title = 'Exports (USD in billions)', 
       caption="Source: TÜİK", 
       y = "Exports",
       x = "Year") +
  theme_classic()

Graph of imports (USD in billions)

ggplot(foreign_trade, aes(x = Date, y = Imports)) +
  geom_bar(stat ='identity', color = 'gray', fill = 'gray') +
  geom_line(stat ='identity', color = 'gray') +
  labs(title = 'Imports (USD in billions)', 
       caption="Source: TÜİK", 
       y = "Imports",
       x = "Year") +
  theme_classic()

Graph of foreign trade balance (USD in billions)

ggplot(foreign_trade, aes(x = Date, y = Balance)) +
  geom_bar(stat ='identity', color = 'brown', fill ='brown') +
  geom_line(stat ='identity', color = 'brown') +
  labs(title = 'Foreign Trade Balance (USD in billions)',
       caption="Source: TÜİK", 
       y = "Balance",
       x = "Year") +
  scale_y_reverse() +
  theme_classic()

Comparison of interest rate and current account deficit

ggplot(foreign_trade, aes(x = Date)) +
  geom_line(aes(y = Deficit, color = 'CAD (USD in billions)')) +
  geom_line(aes(y = Rate, color = 'Interest Rate (%)')) +
  labs(title = 'Current Account Deficit',
       caption="Source: TÜİK, TCMB", 
       y = "",
       x = "Year") +
  theme_classic()

ggplot(foreign_trade, aes(x = Date)) +
  geom_line(aes(y = Deficit, fill = 'CAD (USD in billions)'), color = 'red') +
  geom_smooth(aes(y = Deficit), 
              color = 'red', alpha = TRUE) +
  geom_line(aes(y = Rate), color = 'blue') +
  geom_smooth(aes(y = Rate, color = 'Rate', fill = 'Interest Rate (%)'), 
              color = 'blue', alpha = TRUE) +
  labs(title = 'Current Account Deficit',
       caption="Source: TÜİK, TCMB", 
       y = "",
       x = "Year") +
  theme_classic()